package cta

import (
	"kubequant/apps/cta/strategies"
	"kubequant/trader/datafeed"
)

// NewEngine 创建一个cta engine
func NewEngine() *Engine {
	engine := new(Engine)
	engine.EngineType = LIVE //初始化引擎类型为实盘
	engine.DataFeed = datafeed.GetDataFeed()
	return engine
}

// Engine CTA策略引擎
type Engine struct {
	EngineType     string                              //引擎的类型
	StrategyGroups map[string]strategies.StrategyGroup //k:策略名， v 策略组
	DataFeed       datafeed.BaseDatafeed               //引擎的DataFeed
}

// InitEngine 前端发起该接口,初始化cta引擎
func (engine *Engine) InitEngine() error {
	err := engine.InitDataFeed()
	if err != nil {
		return err
	}
	engine.LoadStrategyGroups()
	return nil
}

// InitDataFeed 初始化数据服务
func (engine *Engine) InitDataFeed() error {
	err := engine.DataFeed.Init()
	if err != nil {
		return err
	}
	return nil
}

// LoadStrategyGroups 加载策略组
func (engine *Engine) LoadStrategyGroups() {
	//加载策略组
	engine.StrategyGroups = strategies.RegisterStrategyGroups()
}

func (engine Engine) Close() {
}
